package com.andon.microcellsimulator.common.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.andon.microcellsimulator.R;

/**
 * Created by Administrator on 2015/6/25.
 */
public class ZnkConfirmWarningDialog extends Dialog {

    public interface OnClickCallBack {
        void exec();
    }

    private Context mContent;

    private ZnkConfirmWarningDialog(Context context){
        super(context, R.style.znk_confirm_dialog);
        mContent = context;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }


    public static ZnkConfirmWarningDialog createDialog(Context context, String message, final OnClickCallBack confirmCallBack, final OnClickCallBack cancelCallBack){

        View view = LayoutInflater.from(context).inflate(R.layout.confirm_warning_dialog, null);
        RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.confirm_view);

        final ZnkConfirmWarningDialog dialog = new ZnkConfirmWarningDialog(context);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setContentView(layout, new RelativeLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));

        TextView confirmContent = (TextView) view.findViewById(R.id.confirm_content);
        Button confirmBtn = (Button) view.findViewById(R.id.confirm_yes);
        Button cancelBtn = (Button) view.findViewById(R.id.confirm_cancel);

        // 设置提示文字
        confirmContent.setText(message);

        confirmBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (confirmCallBack != null) {
                    confirmCallBack.exec();
                }
            }
        });

        cancelBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (cancelCallBack != null) {
                    cancelCallBack.exec();
                }
            }
        });

        return dialog;
    }
}
